package com.swlz.service.impl;

import java.sql.SQLException;

import com.swlz.dao.WebTagDAO;
import com.swlz.entity.WebTag;
import com.swlz.exception.CodeException;
import com.swlz.service.WebTagService;
import com.swlz.vo.PageVO;

/**
 * <pre>
 * 业务逻辑接口具体实现类
 * 网站标签
 * ClassName : com.swlz.service.impl.WebTagServiceImpl
 * Author : swlz
 * E-Mail : 2233875735@qq.com
 * Date : 2020-06-22 05:49:10
 * Version : 1.0
 * Copyright 2020 swlz.top Inc. All rights reserved. 
 * Warning: this content is only for internal circulation of the company. It is forbidden to divulge it or use it for other commercial purposes
 * </pre>
 **/
public class WebTagServiceImpl implements WebTagService {
	
	private WebTagDAO webTagDAO = new WebTagDAO();

	@Override
	public int add(WebTag webTag) throws CodeException {
		try {
			return webTagDAO.insertSelective(webTag);
		} catch (SQLException e) {
			throw new CodeException(500, "添加网站标签错误",e);
		}
	}

	@Override
	public int update(WebTag webTag) throws CodeException {
		try {
			return webTagDAO.updateSelective(webTag);
		} catch (SQLException e) {
			throw new CodeException(501, "修改网站标签错误",e);
		}
	}

	@Override
	public int delete(Long tagId) throws CodeException {
		try {
			return webTagDAO.deleteById(tagId);
		} catch (SQLException e) {
			throw new CodeException(502, "删除网站标签错误",e);
		}
	}

	@Override
	public WebTag get(Long tagId) throws CodeException {
		try {
			return webTagDAO.selectById(tagId);
		} catch (SQLException e) {
			throw new CodeException(503, "获取网站标签失败",e);
		}
	}

	@Override
	public PageVO<WebTag> page(WebTag webTag, Integer current, Integer rowMax) throws CodeException {
		try {
			long total = webTagDAO.countByModel(webTag);
			PageVO<WebTag> page = new PageVO<>(total, current, rowMax);
			return page.setList(webTagDAO.selectByModel(webTag, page.getOffset(), page.getRowMax()));
		} catch (SQLException e) {
			throw new CodeException(504, "获取网站标签分页数据失败",e);
		}
	}


}
